package com.yanqu.road.server.manager.union.huaben.rank;

import com.yanqu.road.entity.rank.cross.CrossUnionWeekRank;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Comparator;

public class CrossUnionWeekRankSort implements Comparator<CrossUnionWeekRank> {

    @Override
    public int compare(CrossUnionWeekRank o1, CrossUnionWeekRank o2) {
        int result = o2.getValue().compareTo(o1.getValue());
        if (result != 0) {
            return result;
        }

        if(!StringUtils.isNullOrEmpty(o1.getParam()) && !StringUtils.isNullOrEmpty(o2.getParam())){
            long val1 = Long.valueOf(o1.getParam());
            long val2 = Long.valueOf(o2.getParam());
            long val = val2 - val1;
            if(val != 0){
                if(val > 0){
                    return -1;
                }else {
                    return 1;
                }
            }
        }

        long time = o1.getLastUpdateTime() - o2.getLastUpdateTime();
        result = time > 0 ? 1 : (time == 0 ? 0 : -1);
        return result;
    }
}
